package com.cndw.kungfu.model.player.domain;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import com.cndw.kungfu.config.ArtifactConfig;
import com.cndw.kungfu.config.ConstantsAct;

/**
 * 单个神器
 * 
 * @author fantadust [9677889@qq.com]
 * @date 2012-8-24 上午9:33:25
 */
public class ArtifactSub implements Serializable {

	private static final long serialVersionUID = -6482368739292793797L;

	private int score;

	private int level;

	private transient int id = 1;

	private Map<Integer, int[]> nodes = new HashMap<Integer, int[]>(6);

	private static final int nodeMax = 6;

	public ArtifactSub() {

	}

	public ArtifactSub(int id) {
		this.id = id;
	}

	public int getScore() {
		return score;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public Map<Integer, int[]> getNodes() {
		return nodes;
	}

	public boolean isIdle(int indexId) {
		return indexId > 0 && indexId <= nodeMax && !nodes.containsKey(indexId);
	}

	public void nodeInstall(int nId, int[] node) {
		nodes.put(nId, node);
	}

	public int[] removeNode(int nId) {
		return nodes.remove(nId);
	}

	public int[] getNode(int nId) {
		return nodes.get(nId);
	}

	public int[] getFourBuff() {
		int[] fourBuff = new int[10];
		for (int[] node : nodes.values()) {
			try {
				if (node[1] > 0 && node[2] >= ArtifactConfig.getAttri(node[1])[4]) {
					fourBuff[node[1]]++;
				}
				if (node[3] > 0 && node[4] >= ArtifactConfig.getAttri(node[3])[4]) {
					fourBuff[node[3]]++;
				}
				if (node[5] > 0 && node[6] >= ArtifactConfig.getAttri(node[5])[4]) {
					fourBuff[node[5]]++;
				}
			} catch (Exception e) {

			}
		}

		return fourBuff;
	}

	public int[] getAttris() {

		int[] eAdd = new int[10];

		for (int[] node : nodes.values()) {
			try {
				eAdd[node[1]] += node[2];
				eAdd[node[3]] += node[4];
				eAdd[node[5]] += node[6];
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
		if (level > 0) {
			for (int i = 0; i < eAdd.length; i++) {
				eAdd[i] = eAdd[i] + eAdd[i] * level / 1000;
			}
		}
		if (id > 0) {
			
			int[] fourbuff = getFourBuff();
			try {
				for (int i = 1; i < fourbuff.length; i++) {
					if (fourbuff[i] >= 3 && ArtifactConfig.isAct(id, i)) {
						eAdd[i] += ArtifactConfig.fourNodeBuff.get(i)[fourbuff[i]];
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}



		return eAdd;
	}
	
	/**
	 * 得到达到3，4，5，6条属性的兵魄个数
	 * 
	 * @param actId
	 * @return
	 */
	public int[] getFourBuffState(int actId) {
		int[] finishCount = new int[4]; 
		int[] tmp = getFourBuff();
		try {
			for (int i = 0; i < finishCount.length; i++) {
				for (int j = 1; j < tmp.length; j++) {
					if (ArtifactConfig.isAct(actId, j)) {
						finishCount[i] += tmp[j] >= ConstantsAct.actFBCondition[i] ? 1 : 0;
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return finishCount;
	}

	public void setId(int id) {
		this.id = id;
	}
	
	
	

}
